package cn.com.self.apis.sms.controller;


import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.com.self.apis.portal.util.ICustomPage;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.self.apis.sms.entity.SmsTbl;
import cn.com.self.apis.sms.service.ISmsTblService;
import cn.com.self.apis.util.CopyUtils;
import cn.com.selfsoft.smartcity.commons.http.DataItem;
import cn.com.selfsoft.smartcity.commons.http.DataPage;
import cn.com.selfsoft.smartcity.commons.http.ResultModel;
import cn.com.selfsoft.smartcity.commons.util.ParameterUtil;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liangwt
 * @since 2020-05-29
 */
@Controller
@RequestMapping("/smsTbl")
@Api(tags = "短信类")
public class SmsTblController {
	@Autowired
	private ISmsTblService smsTblService;
	/**新增短信
     * @Description //TODO
     * @return
     **/
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "新增短信")
    public ResponseEntity create(@RequestBody SmsTbl entity, HttpServletRequest request){
        entity.setCreateDate(new Date());
        entity.setDelFlag("0");
    	SmsTbl create = smsTblService.create(entity);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(create));
    }


    /**分页获取短信列表
     * @Description //TODO
     * @return
     **/
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "分页获取短信列表")
    public ResponseEntity getSmsInfoPage(HttpServletRequest request, Pageable page){
    	Map<String, Object> queryParams = ParameterUtil.HumpToUnderline(request.getParameterMap(), "mark", "size", "page","sort","access_token");
        queryParams.put("del_flag","0");
        ICustomPage<SmsTbl> pageData = this.smsTblService.page(queryParams, page);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(pageData));

    }

    /**获取单个短信信息
     * @Description //TODO
     * @return
     **/
    @RequestMapping(value = {"/load/{id}"}, method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取单个短信信息")
    public ResponseEntity loadSmsInfo(@PathVariable("id") String id,HttpServletRequest request) {
    	SmsTbl smsTbl = this.smsTblService.load(id);
    	return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(new DataItem(smsTbl)));

    }


    /**修改短信信息
     * @Description //TODO
     * @return
     **/

    @RequestMapping(value = {"/update/{id}"}, method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改短信信息")
    public ResponseEntity update(@PathVariable("id") String id, @RequestBody SmsTbl entity, HttpServletRequest request) {
    	SmsTbl smsTbl = this.smsTblService.load(id);
    	CopyUtils.copyProperties(entity, smsTbl);
        smsTbl.setUpdateDate(new Date());
    	SmsTbl update = this.smsTblService.update(smsTbl);
    	return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(new DataItem(update)));

    }


    /**删除短信信息
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "删除短信信息")
    @ResponseBody
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public ResponseEntity deletes(@PathVariable("id") String id){
    	return this.smsTblService.deleteSms(id);
    }
}

